<?php
/* Author: tbloc@cantho.gov.vn */
class Chi_tiet_kiem_ke{  
//Properties
private $KK_ID;
private $HH_ID;
private $CTKK_DON_GIA_NHAP;
private $CTKK_SO_LUONG;
private $CTKK_THANH_TIEN;
private $IS_ACTIVE;
//properties set get 
public function setKK_ID($KK_ID) 
{
	$this->KK_ID = $KK_ID;
}
public function getKK_ID()
{
	return $this->KK_ID;
}	        
public function setHH_ID($HH_ID) 
{
	$this->HH_ID = $HH_ID;
}
public function getHH_ID()
{
	return $this->HH_ID;
}	        
public function setCTKK_DON_GIA_NHAP($CTKK_DON_GIA_NHAP) 
{
	$this->CTKK_DON_GIA_NHAP = $CTKK_DON_GIA_NHAP;
}
public function getCTKK_DON_GIA_NHAP()
{
	return $this->CTKK_DON_GIA_NHAP;
}	        
public function setCTKK_SO_LUONG($CTKK_SO_LUONG) 
{
	$this->CTKK_SO_LUONG = $CTKK_SO_LUONG;
}
public function getCTKK_SO_LUONG()
{
	return $this->CTKK_SO_LUONG;
}	        
public function setCTKK_THANH_TIEN($CTKK_THANH_TIEN) 
{
	$this->CTKK_THANH_TIEN = $CTKK_THANH_TIEN;
}
public function getCTKK_THANH_TIEN()
{
	return $this->CTKK_THANH_TIEN;
}	        
public function setIS_ACTIVE($IS_ACTIVE) 
{
	$this->IS_ACTIVE = $IS_ACTIVE;
}
public function getIS_ACTIVE()
{
	return $this->IS_ACTIVE;
}	        
//crud methods
public function insert($db = null) {
	if ($db != null){
	$sql = "INSERT INTO `chi_tiet_kiem_ke`(                        
			`KK_ID`, 
				`HH_ID`, 
				`CTKK_DON_GIA_NHAP`, 
				`CTKK_SO_LUONG`, 
				`CTKK_THANH_TIEN`, 
				`IS_ACTIVE` 
		)
	VALUES(
    		:KK_ID, 
	    		:HH_ID, 
	    		:CTKK_DON_GIA_NHAP, 
	    		:CTKK_SO_LUONG, 
	    		:CTKK_THANH_TIEN, 
	    		:IS_ACTIVE 
	    );";
	$parameters = array(
			":KK_ID", 
				":HH_ID", 
				":CTKK_DON_GIA_NHAP", 
				":CTKK_SO_LUONG", 
				":CTKK_THANH_TIEN", 
				":IS_ACTIVE" 
		);
    $values = array(  
    		$this->getKK_ID(), 
	    		$this->getHH_ID(), 
	    		$this->getCTKK_DON_GIA_NHAP(), 
	    		$this->getCTKK_SO_LUONG(), 
	    		$this->getCTKK_THANH_TIEN(), 
	    		$this->getIS_ACTIVE() 
	    );
    $types = array(
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    );
	$lastInsertID = $db->executeNonQuery($sql, $parameters, $values, $types, true);
	$this->setHH_ID($lastInsertID);
    }
}
	
	public function delete($db = null) {
	    if ($db != null) {
	        $sql = "delete from `chi_tiet_kiem_ke`
	                where `KK_ID` = :KK_ID;";
	        $parameters = array(":KK_ID");
	        $values = array($this->getKK_ID());
	        $types = array(PDO::PARAM_INT);//Kiem tra lai kieu du lieu nhe
	        $result = $db->executeNonQuery($sql, $parameters, $values, $types);
	        return $result;
	    }
	}
	
	public function update($db = null) {
	        if ($db != null) {
	            $sql = "UPDATE `chi_tiet_kiem_ke` SET 
			`KK_ID`=:KK_ID,
				`HH_ID`=:HH_ID,
				`CTKK_DON_GIA_NHAP`=:CTKK_DON_GIA_NHAP,
				`CTKK_SO_LUONG`=:CTKK_SO_LUONG,
				`CTKK_THANH_TIEN`=:CTKK_THANH_TIEN,
				`IS_ACTIVE`=:IS_ACTIVE
			WHERE `HH_ID` = :HH_ID;";
	            $parameters = array(
			":KK_ID",
				":HH_ID",
				":CTKK_DON_GIA_NHAP",
				":CTKK_SO_LUONG",
				":CTKK_THANH_TIEN",
				":IS_ACTIVE"
			);
	// Kiem tra dau , nhe
	$values = array(  
			$this->getKK_ID(),
				$this->getHH_ID(),
				$this->getCTKK_DON_GIA_NHAP(),
				$this->getCTKK_SO_LUONG(),
				$this->getCTKK_THANH_TIEN(),
				$this->getIS_ACTIVE()
		);
    $types = array(
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    );
	$result = $db->executeNonQuery($sql, $parameters, $values, $types);
	return $result;
	        }
	 }
	 
	public function getByID($kiemke,$hanghoa,$db = null) {
	if ($db != null) {
	$sql = "SELECT
			`KK_ID`,
				`HH_ID`,
				`CTKK_DON_GIA_NHAP`,
				`CTKK_SO_LUONG`,
				`CTKK_THANH_TIEN`,
				`IS_ACTIVE`
			FROM `chi_tiet_kiem_ke` WHERE `KK_ID`=:KK_ID and `HH_ID` = :HH_ID and `is_active`=1;";
	$parameters = array(":KK_ID",":HH_ID");
	$values = array($kiemke,$hanghoa);
	$types = array(PDO::PARAM_INT,PDO::PARAM_INT);//kiem tra lai kieu du lieu nhe
	$rows = $db->executeQuery($sql, $parameters, $values, $types);
	if ($rows != null) {
	$row = $rows->fetch();
        $chitietkiemke=new Chi_tiet_kiem_ke();
		$chitietkiemke->setKK_ID($row->KK_ID);
		$chitietkiemke->setHH_ID($row->HH_ID);
		$chitietkiemke->setCTKK_DON_GIA_NHAP($row->CTKK_DON_GIA_NHAP);
		$chitietkiemke->setCTKK_SO_LUONG($row->CTKK_SO_LUONG);
		$chitietkiemke->setCTKK_THANH_TIEN($row->CTKK_THANH_TIEN);
		$chitietkiemke->setIS_ACTIVE($row->IS_ACTIVE);
	
                return $chitietkiemke;
        }
	
		}
	}
	
	public function getList($db = null) {
	if ($db != null) {
    $sql = "SELECT
			`KK_ID`,
				`HH_ID`,
				`CTKK_DON_GIA_NHAP`,
				`CTKK_SO_LUONG`,
				`CTKK_THANH_TIEN`,
				`IS_ACTIVE`
			FROM `chi_tiet_kiem_ke` WHERE `is_active`=1;";
    $rows = $db->executeQuery($sql);
    $objects = array();
    if ($rows != null) {
    while ($row = $rows->fetch()) {
    $obj = new chi_tiet_kiem_ke();
    	 $obj->setKK_ID($row->KK_ID);
		 $obj->setHH_ID($row->HH_ID);
		 $obj->setCTKK_DON_GIA_NHAP($row->CTKK_DON_GIA_NHAP);
		 $obj->setCTKK_SO_LUONG($row->CTKK_SO_LUONG);
		 $obj->setCTKK_THANH_TIEN($row->CTKK_THANH_TIEN);
		 $obj->setIS_ACTIVE($row->IS_ACTIVE);
		$objects[] = $obj;
    }
    return $objects;
    }
        }
    }
}
?>

